package com.eco.fanliapp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eco.fanliapp.dao.AppUserOrderMapper;
import com.eco.fanliapp.entity.AppUserOrder;
import com.eco.fanliapp.entity.JdUserOrder;
import com.eco.fanliapp.entity.PddUserOrder;
import com.eco.fanliapp.service.IAppUserOrderService;
import com.eco.fanliapp.utils.Convert;
import com.eco.fanliapp.utils.DateUtils;
import com.eco.fanliapp.vo.AppUserFansTeamVo;
import com.eco.fanliapp.vo.SyChannelUserVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户和订单中间 服务层实现
 * 
 * @author xiaoxx
 * @date 2019-04-24
 */
@Service
public class AppUserOrderServiceImpl extends ServiceImpl<AppUserOrderMapper, AppUserOrder> implements IAppUserOrderService
{
	@Autowired
	private AppUserOrderMapper appUserOrderMapper;

	/**
     * 查询用户和订单中间信息
     * 
     * @param tableId 用户和订单中间ID
     * @return 用户和订单中间信息
     */
    @Override
	public AppUserOrder selectAppUserOrderById(Integer tableId)
	{
	    return appUserOrderMapper.selectAppUserOrderById(tableId);
	}
	
	/**
     * 查询用户和订单中间列表
     * 
     * @param appUserOrder 用户和订单中间信息
     * @return 用户和订单中间集合
     */
	@Override
	public List<AppUserOrder> selectAppUserOrderList(AppUserOrder appUserOrder)
	{
	    return appUserOrderMapper.selectAppUserOrderList(appUserOrder);
	}
	
    /**
     * 新增用户和订单中间
     * 
     * @param appUserOrder 用户和订单中间信息
     * @return 结果
     */
	@Override
	public int insertAppUserOrder(AppUserOrder appUserOrder)
	{
		appUserOrder.setTableCreateTime(System.currentTimeMillis());
		appUserOrder.setTableUpdateTime(System.currentTimeMillis());
	    return appUserOrderMapper.insertAppUserOrder(appUserOrder);
	}
	
	/**
     * 修改用户和订单中间
     * 
     * @param appUserOrder 用户和订单中间信息
     * @return 结果
     */
	@Override
	public int updateAppUserOrder(AppUserOrder appUserOrder)
	{
		appUserOrder.setTableUpdateTime(System.currentTimeMillis());
	    return appUserOrderMapper.updateAppUserOrder(appUserOrder);
	}

	/**
     * 删除用户和订单中间对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
	@Override
	public int deleteAppUserOrderByIds(String ids)
	{
		return appUserOrderMapper.deleteAppUserOrderByIds(Convert.toStrArray(ids));
	}

	@Override
	public AppUserOrder selectAppUserOrderBybalanceCount(Long userId) {
		// TODO Auto-generated method stub
		return appUserOrderMapper.selectAppUserOrderBybalanceCount(userId);
	}

	@Override
	public int countBingOrderSum(Long userId) {
		//TODO 计算用户绑定订单数（付款订单）
		return appUserOrderMapper.countBingOrderSum(userId);
	}

	@Override
	public AppUserOrder selectAppUserOrderByTradeId(Long tradeId) {
		// TODO Auto-generated method selectAppUserOrderByTradeId查询用户订单是否已经处理过
		return appUserOrderMapper.selectAppUserOrderByTradeId(tradeId);
	}

	@Override
	public List<AppUserOrder> selectAppUserOrderListByTradeId(Long tradeId) {
		// TODO Auto-generated method stub 
		return appUserOrderMapper.selectAppUserOrderListByTradeId(tradeId);
	}

	@Override
	public double findBalanceListByUserId(Long userId, int i) {
		// TODO Auto-generated method findBalanceListByUserId
		return appUserOrderMapper.findBalanceListByUserId(userId,i);
	}

	@Override
	public HashMap<String, Object> findFansSuperBalanceSumByUserId(List<Long> userId, int i) {
		// TODO Auto-generated method findFansSuperBalanceSumByUserId
		return appUserOrderMapper.findFansSuperBalanceSumByUserId(userId,i);
	}

	@Override
	public String findFansLevelBalanceSumByUserId(Long userId, int i) {
		// TODO Auto-generated method findFansLevelBalanceSumByUserId
		return appUserOrderMapper.findFansLevelBalanceSumByUserId(userId,i);
	}

	@Override
	public List<AppUserOrder> selectLargeAmountYesList(Long starTime,Long endTime) {
		// TODO Auto-generated method selectLargeAmountYesList
		return appUserOrderMapper.selectLargeAmountYesList(starTime,endTime);
	}

	@Override
	public List<AppUserOrder> selectAppUserOrderByUserId(Long userId) {
		// TODO Auto-generated method stub
		return appUserOrderMapper.selectAppUserOrderByUserId(userId);
	}

	@Override
	public List<AppUserOrder> selectAppUserOrderByUserIdAndTkStatus3(Long userId) {
		// TODO Auto-generated method stub
		return appUserOrderMapper.selectAppUserOrderByUserIdAndTkStatus3(userId);
	}

	@Override
	public HashMap<String, Object> findBalanceByUserIdSum(Long userId, int i) {
		// TODO Auto-generated method stub
		return appUserOrderMapper.findBalanceByUserIdSum(userId,i);
	}
	/**
	 * 查询订单数量（根据userId）
	 * @param userIds
	 * @return
	 */
	@Override
	public int buyNumByAllId(List<Long> userIds){
		return appUserOrderMapper.buyNumByAllId(userIds);
	}

	/**
	 * 查询用户购买免单商品订单数量（根据userId）
	 *
	 * @param taobaoUserId
	 * @return
	 */
	@Override
	public int buyFreeNumByAllId(Long taobaoUserId) {
		return appUserOrderMapper.buyFreeNumByAllId(taobaoUserId);
	}

	@Override
	public AppUserOrder findUserIdOrderId(Long userId, Long tradeId) {
		// TODO Auto-generated method stub 查询用户订单分佣金额
		return appUserOrderMapper.findUserIdOrderId(userId,tradeId);
	}

	/**
	 * 取我的收益-入账中订单-包含自己订单，直接粉丝订单，间接粉丝订单，分享赚订单     tkStatus = 12
	 *
	 * @param userId
	 * @param invoCode
	 * @return
	 */
	@Override
	public List<AppUserOrder> getMeBookedOrderDetail(Long userId, String invoCode, Integer pageNum, Integer pageSize) {

		// TODO Auto-generated method stub
		return appUserOrderMapper.getMeBookedOrderDetail(userId, invoCode, pageNum, pageSize);
	}

	@Override
	public List<AppUserOrder> selectUserOrder(Long userId) {
		return appUserOrderMapper.selectUserOrder(userId);
	}

	/**
	 * 我的团队-->>我的下级
	 * @param userId
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	@Override
	public List<AppUserFansTeamVo> findFansTeamList(Long userId, Integer pageNum, Integer pageSize) {
		return appUserOrderMapper.findFansTeamList(userId,pageNum,pageSize);
	}

	@Override
	public Double statisticsCommission(Integer flag, Integer companyId, long startTime, long endTime) {
		return appUserOrderMapper.statisticsCommission(flag,companyId,startTime,endTime);
	}

	@Override
	public Integer yesterdayOrderRepeat(Integer companyId, Integer flag, long startTime, long endTime) {
		return appUserOrderMapper.yesterdayOrderRepeat(companyId,flag, startTime, endTime);
	}


	@Override
	public double singleZeroPurchaseCost(Integer companyId, Integer flag, long startTime, long endTime) {
		return appUserOrderMapper.singleZeroPurchaseCost(companyId,flag, startTime, endTime);
	}

	@Override
	public double yesterdayZeroPurchaseCost() {
		return appUserOrderMapper.yesterdayZeroPurchaseCost();
	}

	@Override
	public int firstShareRatio(Integer companyId, Integer flag, long startTime, long endTime) {
		return appUserOrderMapper.firstShareRatio(companyId, flag, startTime,endTime);
	}

	@Override
	public int yesterdayFirstShareRatio() {
		return appUserOrderMapper.yesterdayFirstShareRatio();
	}

	@Override
	public Integer yesterdayAddingUsers(Integer companyId,Integer flag) {
		return appUserOrderMapper.yesterdayAddingUsers(companyId,flag);
	}

	@Override
	public String singleInitialCost(Integer companyId, Integer flag) {
		return appUserOrderMapper.singleInitialCost(companyId,flag);
	}

	@Override
	public Integer yesterdaySubsidyFreeAmount(Integer companyId) {
		return appUserOrderMapper.yesterdaySubsidyFreeAmount(companyId);
	}

	@Override
	public Double freeAllianceCommissionYesterday(Integer companyId,Integer type,Long startDate,Long endDate) {
		return appUserOrderMapper.freeAllianceCommissionYesterday(companyId,type,startDate,endDate);
	}

	@Override
	public Integer totalOrderUserRegistration(Integer companyId) {
		return appUserOrderMapper.totalOrderUserRegistration(companyId);
	}

	@Override
	public Integer yesterdayOrderQuantity(Integer companyId) {
		return appUserOrderMapper.yesterdayOrderQuantity(companyId);
	}

	@Override
	public Integer selectTotalOrder(Integer companyId, Integer flag, long startTime, long endTime) {
		return appUserOrderMapper.selectTotalOrder(companyId,flag,startTime,endTime);
	}

	@Override
	public Double timeLimitedCommission(Integer companyId, Integer flag,Integer types) {
		return appUserOrderMapper.timeLimitedCommission(companyId,flag,types);
	}

	@Override
	public String todayHotCommission(Integer companyId, Integer flag) {
		return appUserOrderMapper.todayHotCommission(companyId,flag);
	}

	@Override
	public String voucherCommission(Integer companyId, Integer flag) {
		return appUserOrderMapper.voucherCommission(companyId,flag);
	}

	@Override
	public Integer getOrderCountNumber(Long userId) {
		return  appUserOrderMapper.getOrderCountNumber(userId);
	}

    /**
     * 判断是否有提现权限
     * @param userId
     * @return
     */
    @Override
    public Boolean withdrawPermissionCount(Long userId) {
        Integer count_one = appUserOrderMapper.withdrawPermissionCount(userId);
        if(count_one >=2){
            return true;
        }else if(count_one == 1){
            Integer count_two = appUserOrderMapper.withdrawPermissionCountTwo(userId);
            if(count_two == 1){
                return false;
            }else {
                return true;
            }
        }
        return false;
    }

    @Override
	public Double singleFixedReturnYesterday(Integer companyId, Integer flag) {
		return appUserOrderMapper.singleFixedReturnYesterday(companyId,flag);
	}

	@Override
	public SyChannelUserVO selectOrderMessage(Long channelId, String searchDate) {
		return appUserOrderMapper.selectOrderMessage(channelId,searchDate);
	}

	@Override
	public Integer selectOrderUser(Long companyId, Integer flag,Integer freeFlag) {
		return appUserOrderMapper.selectOrderUser(companyId,flag,freeFlag);
	}

	@Override
	public Integer recommendedOrderNum(Integer companyId, Integer flag, Integer types) {
    	return appUserOrderMapper.recommendedOrderNum(companyId,flag,types);
	}

	@Override
	public Integer OrderRepeat(Integer companyId) {
		return appUserOrderMapper.OrderRepeat(companyId);
	}

	@Override
	public Double channelPubSharereFee(Integer companyId, Integer groupId, Integer flag) {
		return appUserOrderMapper.channelPubSharereFee(companyId,groupId,flag);
	}

	@Override
	public Double pubCommisssionPubSharePreFee(Integer companyId, Integer type, Long startDate, Long endDate) {
		return appUserOrderMapper.pubCommisssionPubSharePreFee(companyId,type,startDate,endDate);
	}

	@Override
	public Integer payOrderTotalNum(Integer companyId, Integer type, Long startDate, Long endDate) {
		return appUserOrderMapper.payOrderTotalNum(companyId,type,startDate,endDate);
	}

	@Override
	public Double payOrderTotalMoney(Integer companyId, Integer type, Long startDate, Long endDate) {
		return appUserOrderMapper.payOrderTotalMoney(companyId,type,startDate,endDate);
	}

	@Override
	public int totalGoodFreesNum(Integer companyId, Integer orderType, Integer type, Long startDate, Long endDate) {
		return appUserOrderMapper.totalGoodFreesNum(companyId,orderType,type,startDate,endDate);
	}

	@Override
	public Double totalGoodFreesMoney(Integer companyId, Integer orderType, Integer type, Long startDate, Long endDate) {
		return appUserOrderMapper.totalGoodFreesMoney(companyId,orderType,type,startDate,endDate);
	}

	@Override
	public Integer sqjdOrderNum() {
		return appUserOrderMapper.sqjdOrderNum();
	}

	@Override
	public Map<String, Double> sqjdCommision() {
		return appUserOrderMapper.sqjdCommision();
	}

	@Override
	public Map<String, Double> sqjdTypeCommision(Integer companyId,Integer orderType,Integer goodFrees) {
		return appUserOrderMapper.sqjdTypeCommision(companyId,orderType,goodFrees);
	}

	@Override
	public Integer sqjdAllOrderNum() {
		return appUserOrderMapper.sqjdAllOrderNum();
	}

	@Override
	public Map<String,Object> freeCommssion() {
		return appUserOrderMapper.freeCommssion();
	}

	@Override
	public Double zgsAllCommission() {
		return appUserOrderMapper.zgsAllCommission();
	}

	@Override
	public Map<String, Object> selectChannelNums(Integer type) {
		return appUserOrderMapper.selectChannelNums(type);
	}

	@Override
	public JdUserOrder selectJdOrderBybalanceCount(Long userId) {
		return appUserOrderMapper.selectJdOrderBybalanceCount(userId);
	}

	@Override
	public PddUserOrder selectPddOrderBybalanceCount(Long userId) {
		return appUserOrderMapper.selectPddOrderBybalanceCount(userId);
	}

	@Override
	public JdUserOrder selectUserJdOrder(Long userId) {
		return appUserOrderMapper.selectUserJdOrder(userId);
	}

	@Override
	public PddUserOrder selectUserPddOrder(Long userId) {
		return appUserOrderMapper.selectUserPddOrder(userId);
	}

}
